package com.coderush.admin.sys.controller;


import com.coderush.admin.core.response.Result;
import com.coderush.admin.sys.model.dto.LoginDto;
import com.coderush.admin.sys.model.vo.VerifyCodeVo;
import com.coderush.admin.sys.service.LoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * PackageName com.stellarforce.admin.sys.controller
 *
 * @Author Eason
 * @Version v1.0
 * @ClassName LoginController
 * @Date 2025/8/18
 * @Description TODO
 */
@RestController
@RequestMapping("/sys")
@RequiredArgsConstructor
public class LoginController {

    private final LoginService loginService;

    /**
     * 获取验证码
     */
    @Operation(summary = "获取验证码", description = "获取验证码")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "成功"),
            @ApiResponse(responseCode = "401", description = "未授权"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    @GetMapping("/getVerifyCode")
    public Result<VerifyCodeVo> getVerifyCode() {
        return Result.buildSuccess(loginService.getVerifyCode());
    }


    /**
     * 员工登录
     * @param loginDto
     * @return
     */
    @Operation(summary = "员工登录", description = "员工登录")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "成功"),
            @ApiResponse(responseCode = "401", description = "未授权"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    @PostMapping("/login")
    public Result<String> login(@Valid @RequestBody LoginDto loginDto) {

        var accessToken = loginService.login(loginDto);

        return Result.buildSuccess(accessToken);
    }

    /**
     * 员工登出
     *
     * @return
     */
    @Operation(summary = "员工登出", description = "员工登出")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "成功"),
            @ApiResponse(responseCode = "401", description = "未授权"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    @GetMapping("/logout")
    public Result<String> logout() {
        loginService.logout();
        return Result.buildSuccess("登出成功");
    }


}